package com.mlethe.android.demo.ripple;

import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.mlethe.android.demo.R;
import com.mlethe.library.widget.ripple.RippleView;

public class MainRippleActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_ripple);
        RippleView mWaveView = findViewById(R.id.wave_view);
        RippleView forwardBtn = findViewById(R.id.forwardBtn);
        FowardBackView arrowView = findViewById(R.id.arrowView);
        arrowView.setDefaultResId(R.mipmap.ic_parking_forward)
                .setMoveResId(R.mipmap.ic_parking_arrow_foward)
                .setFoward(true);
        RippleView turnRightRv = findViewById(R.id.turnRightRv);
        mWaveView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    mWaveView.setCenterRadius(85f)
                            .setCenterImageId(R.mipmap.ic_parking_running)
                            .start();
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                    mWaveView.setCenterRadius(93f)
                            .setCenterImageId(R.mipmap.ic_parking_normal)
                            .stop();
                }
                return true;
            }
        });
        forwardBtn.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    if (forwardBtn != null) {
                        forwardBtn.setCenterRadius(58f)
                                .start();
                    }
                    if (arrowView != null) {
                        arrowView.startAnimator();
                    }
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (forwardBtn != null) {
                        forwardBtn.setCenterRadius((int)getResources().getDimension(R.dimen.dp_67))
                                .stop();
                    }
                    if (arrowView != null) {
                        arrowView.stopAnimator();
                    }
                }
                return true;
            }
        });
        turnRightRv.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    if (turnRightRv != null) {
                        turnRightRv.start();
                    }
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (turnRightRv != null) {
                        turnRightRv.stop();
                    }
                }
                return true;
            }
        });
        /*mWaveView.postDelayed(new Runnable() {
            @Override
            public void run() {
                mWaveView.stopImmediately();
            }
        }, 10000);*/
    }
}
